package com.sudoku.board;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;

import com.sudoku.utility.Constants;

public class Debug implements Constants{
    private HashSet<Integer> base = new HashSet<Integer>();
    private final ArrayList<Integer> BoxNumbers = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
    private Board board;
    
    public Debug(Board board){
        this.board=board;
        refillBase();
    }
    
    /**
     * Fill in all blank tiles with penciled numbers
     */
    public void pencilAllTiles() {
        for (Box box : board.getData()) {
            for (Tile tile : box.getData()) {
                if (tile.isBlank()) {
                    tile.clearPencilNumbers();
                    pencilTile(tile, box);
                }
            }
        }
    }

    private void pencilTile(Tile tile, Box box) {
        // determine numbers in row
        base.removeAll(board.getBoardRow((int) ((ROWS_PER_BOX - 1 - box.getCoords().y) * BOXES_PER_BOARD + ROWS_PER_BOX - 1 - tile.getCoords().y)));
        // determine numbers in column
        base.removeAll(board.getBoardCol((int) ((box.getCoords().x * BOXES_PER_BOARD + tile.getCoords().x))));
        // determine numbers in box
        base.removeAll(box.getNumbers());
        tile.getPencilNumbers().addAll(base);
        refillBase();
    }
    
    public void refillBase() {
        base.addAll(BoxNumbers);
    }

}
